// $Id: uuid_ptr.hpp 2 2009-09-02 08:47:42Z joseph2002 $
/*
 * Copyright 2009 Joseph Wu
 * Distributed under the Boost Software License, Version 1.0.
 * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
 *
 * For more information, see http://xpcomplus.sourceforge.net
 */

#ifndef XPCOM_PROXY_UUID_PTR_HPP
#define XPCOM_PROXY_UUID_PTR_HPP

#include <xpcom/config.hpp>
#include <boost/noncopyable.hpp>
#include <xpcom/uuid.hpp>

#ifdef BOOST_HAS_ABI_HEADERS
#include BOOST_ABI_PREFIX
#endif

namespace xpcom {
namespace proxy {

//
// XPCOM proxy argument translators.
//
// uuid_ptr_in(const uuid&) --> const uuid*
// uuid_ptr_out(uuid&) --> uuid**
// uuid_ptr_inout(uuid&) --> uuid**
//
// Note: null pointer is mapped to uuid::nil
//

XPCOM_FORCEINLINE
const uuid* uuid_ptr_in(const uuid& id)
{
    return id.is_nil() ? 0 : &id;
}

class uuid_ptr_out : boost::noncopyable
{
public:
    XPCOM_DECL explicit uuid_ptr_out(uuid& id);
    XPCOM_DECL ~uuid_ptr_out();

    XPCOM_FORCEINLINE
    operator uuid**()
    {
        return &val_;
    }

private:
    uuid& id_;
    uuid* val_;
};

class uuid_ptr_inout : boost::noncopyable
{
public:
    XPCOM_DECL explicit uuid_ptr_inout(uuid& id);
    XPCOM_DECL ~uuid_ptr_inout();

    XPCOM_FORCEINLINE
    operator uuid**()
    {
        return &val_;
    }

private:
    uuid& id_;
    uuid* val_;
};

} // namespace xpcom::proxy
} // namespace xpcom

#ifdef BOOST_HAS_ABI_HEADERS
#include BOOST_ABI_SUFFIX
#endif

#endif // XPCOM_PROXY_UUID_PTR_HPP
